//
//  PersonInfoViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/4/15.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "PersonInfoViewController.h"
#import "ThreeLevelPickerView.h"
#import "UICustomActionSheet.h"
#import "STActionSheet.h"
#import "DZNPhotoEditorViewController.h"
#import "UIImagePickerController+Edit.h"

#import "ScroButton.h"
#import "ChoosePageViewController.h"
@interface PersonInfoViewController ()
<UIActionSheetDelegate>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (weak, nonatomic) IBOutlet UIButton *commitButton;

@property (strong, nonatomic) IBOutlet UIImageView *personHead;//头像
@property (strong, nonatomic) IBOutlet UITextField *nickNameLabel;//昵称

@property (strong, nonatomic) IBOutlet UITextField *nameLabel;//名字
@property (strong, nonatomic) IBOutlet UITextField *birthdayField;//生日

@property (strong, nonatomic) IBOutlet UITextField *phoneNomber;//手机号
@property (strong, nonatomic) IBOutlet UITextField *email;//邮箱
@property (weak, nonatomic) IBOutlet UITextField *addressField;//地址
@property (weak, nonatomic) IBOutlet UITextField *userType;//用户类型
@property (weak, nonatomic) IBOutlet UITextField *idCdard;//身份证号
@property (weak, nonatomic) IBOutlet UITextField *companyName;//公司名字
@property(nonatomic,strong)ScroButton * sexButton;

@property (strong, nonatomic) IBOutlet UIButton *maskButton;
@property (strong, nonatomic) IBOutlet UIView *changeImageView;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;

@property(nonatomic,strong)NSString * headImageStr;
@end

@implementation PersonInfoViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hadLogin) name:@"hadLogin" object:nil];
    _headImageStr = @"1";
    
    [self initViewLayout];
    if (!_isRegistered) {
        [self getUserInfo];
    }
    
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    [self adaptiveViewLayout:self.changeImageView];
    _scroview.contentSize = flexibleSize(CGSizeMake(0, 620), NO);
    _personHead.layer.masksToBounds = YES;
    _personHead.layer.cornerRadius = 25*VerticalRatio();
    
    _commitButton.layer.cornerRadius = 4*VerticalRatio();

    ScroButton * button = [[ScroButton alloc]initWithFrame:flexibleFrame(CGRectMake(233, 163, 50, 24), NO)];
    button.defaultColor = [UIColor colorWithRed:0.988 green:0.439 blue:0.035 alpha:1.000];
    button.selectedColor = [UIColor colorWithRed:0.063 green:0.506 blue:0.835 alpha:1.000];
    button.defaultTitle = @"女";
    button.selectedTitle = @"男";
    button.circleColor = [UIColor whiteColor];
    button.textColor = [UIColor whiteColor];
    button.textFont = [UIFont systemFontOfSize:15*VerticalTexeRatio()];
    button.ifSelected = YES;
    button.changeSelected = ^(BOOL ifSelected){
        
    };
    [self.scroview addSubview:button];
    _sexButton = button;
    
    if (_isRegistered) {
        _titleLabel.text = @"完善资料";
        _userType.userInteractionEnabled = YES;
    } else if (!_isRegistered) {
        _titleLabel.text = @"个人资料";
        _userType.userInteractionEnabled = NO;
    }
    
    
   
    
}

- (IBAction)back:(id)sender {
    if (_isRegistered) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }else{
     [self backBtn];
    }
}

- (void)hadLogin{
    [self backBtn];
}



#pragma mark=====获取用户信息
- (void)getUserInfo{

    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryMemberInfoById withHttpType:@"POST" withTag: GS_GS_queryMemberInfoById];
    
}



#pragma mark == 确认修改
- (IBAction)savePersonInfo:(id)sender {

    [self ModifyTheData];
}

#pragma mark == 修改资料/注册提交资料
- (void)ModifyTheData {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    if ([Common dataIsNULL:_phoneNomber.text]) {
        [CWHUDTips showTips:_phoneNomber.placeholder];
        return;
    }
    if ([Common dataIsNULL:_nameLabel.text]) {
        [CWHUDTips showTips:_nameLabel.placeholder];
        return;
    }
    if ([Common dataIsNULL:_addressField.text]) {
        [CWHUDTips showTips:_addressField.placeholder];
        return;
    }
    if ([Common dataIsNULL:_idCdard.text]) {
        [CWHUDTips showTips:_idCdard.placeholder];
        return;
    }
    if ([Common dataIsNULL:_companyName.text]) {
        [CWHUDTips showTips:_companyName.placeholder];
        return;
    }
    if ([Common dataIsNULL:_email.text]) {
        [CWHUDTips showTips:_email.placeholder];
        return;
    }
    if ([Common dataIsNULL:_nickNameLabel.text]) {
        [CWHUDTips showTips:_nickNameLabel.placeholder];
        return;
    }
    if ([Common dataIsNULL:_headImageStr]) {
        [CWHUDTips showTips:@"请选择用户头像"];
        return;
    }
    if ([Common dataIsNULL:_birthdayField.text]) {
        [CWHUDTips showTips:_birthdayField.placeholder];
        return;
    }
   
    if (_sexButton.ifSelected) {
        [dic setObject:@"1" forKey:@"museSex"];
    }else{
        [dic setObject:@"2" forKey:@"museSex"];
    }
    if ([_userType.text isEqualToString:@"工程公司"]) {
        [dic setObject:@"4" forKey:@"museType"];
    }else if ([_userType.text isEqualToString:@"设计师"]){
        [dic setObject:@"5" forKey:@"museType"];
    }else{
        [dic setObject:@"6" forKey:@"museType"];
    }
        [dic setObject:_phoneNomber.text forKey:@"musePhone"];
        [dic setObject:_nameLabel.text forKey:@"museTrueName"];
        [dic setObject:_addressField.text forKey:@"museAddress"];
        [dic setObject:_idCdard.text forKey:@"museIdcardNo"];
        [dic setObject:_companyName.text forKey:@"museCompanyName"];
        [dic setObject:_email.text forKey:@"museEmail"];
        [dic setObject:_nickNameLabel.text forKey:@"museNickName"];
        [dic setObject:_headImageStr forKey:@"museImage"];
        [dic setObject:[_birthdayField.text substringToIndex:10] forKey:@"museBirthday"];
    
    
        NSString * lan = [InternationalControl userLanguage];
        if ([lan isEqualToString:@"en"]) {
            [dic setObject:@"2" forKey:@"language"];
        }else{
            [dic setObject:@"1" forKey:@"language"];
        }
    
        self.shareApi.delegate=self;
    if (_isRegistered==YES) {
        if ([Common dataIsNULL:_userType.text]) {
            [CWHUDTips showTips:_userType.placeholder];
            return;
        }
        [dic setObject:_password forKey:@"password"];
        [dic setObject:_userName forKey:@"userName"];
        [dic setObject:_code forKey:@"code"];
        [self.shareApi  requestOperationWithDic:dic withPath:GS_appUserRegister withHttpType:@"POST" withTag:GS_GS_appUserRegister];
    }else{
        [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        [self.shareApi  requestOperationWithDic:dic withPath:GS_updateMember withHttpType:@"POST" withTag:GS_GS_updateMember];
    }

}

#pragma mark == 修改头像
- (IBAction)changeHeadImage:(id)sender {
    [self hideKeyBoard];
    _changeImageView.hidden = NO;
    _maskButton.hidden = NO;
}

#pragma mark == 取消
- (IBAction)hidden:(id)sender {
    _changeImageView.hidden = YES;
    _maskButton.hidden = YES;
}

#pragma mark == 修改生日
- (IBAction)changeBrithday:(id)sender {
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    
    NSDate * date  = [[NSDate alloc]init];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];//格式化
    [formatter setDateFormat:@"yyyy-MM-dd"];
    [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"] ];
    NSString * string =[formatter stringFromDate:date];
    NSInteger Year = [[string substringToIndex:4]integerValue];
    NSInteger Month = [[string substringWithRange:NSMakeRange(5, 2)]integerValue];
    NSInteger  Day = [[string substringFromIndex:8]integerValue];
    if (_birthdayField.text.length>=10) {
        Year = [[_birthdayField.text substringToIndex:4]integerValue];
        Month = [[_birthdayField.text substringWithRange:NSMakeRange(5, 2)]integerValue];
        Day = [[_birthdayField.text substringFromIndex:8]integerValue];
    }
    
    
    ThreeLevelPickerView * pickerView = [[ThreeLevelPickerView alloc]initWithSelectedAtRows:@[@(Year-1),@(Month-1),@(Day-1)] complect:^(NSString *str) {
        _birthdayField.text = str;
    }];
    [pickerView show];

}



#pragma mark == 选择上传照片方式
- (IBAction)chosePhoto:(UIButton *)sender {
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        UICustomActionSheet* actionSheet = [[UICustomActionSheet alloc] initWithTitle:@"" delegate:nil buttonTitles:@[@"",@""]];
        
        [actionSheet setButtonColors:@[[UIColor clearColor]]];
        [actionSheet setBackgroundColor:[UIColor clearColor]];
        
        [actionSheet setSubtitle:@""];
        [actionSheet setSubtitleColor:[UIColor clearColor]];
        
        [actionSheet showInView:self.view];
        
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        __weak __typeof(self)weakSelf = self;
        [actionSheet hideAlert];
        if (sender.tag==100){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                self.personHead.image = image;
                self.personHead.layer.masksToBounds = YES;
                self.personHead.layer.cornerRadius = 25*VerticalRatio();
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }else if (sender.tag==101){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                self.personHead.image = image;
                self.personHead.layer.masksToBounds = YES;
                self.personHead.layer.cornerRadius = 25*VerticalRatio();
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }
        
        
        
        
    }else {
        UIActionSheet *ss=[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:@"" otherButtonTitles:@"", nil];
        [ss showInView:self.view];
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        __weak __typeof(self)weakSelf = self;
        [ss dismissWithClickedButtonIndex:0 animated:YES];
        if (sender.tag==100){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                self.personHead.image = image;
                self.personHead.layer.masksToBounds = YES;
                self.personHead.layer.cornerRadius = 25*VerticalRatio();
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }else if (sender.tag==101){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                self.personHead.image = image;
                self.personHead.layer.masksToBounds = YES;
                self.personHead.layer.cornerRadius = 25*VerticalRatio();
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }
        
        
        
    }
    
    _changeImageView.hidden = YES;
    _maskButton.hidden = YES;
}

#pragma mark == 取消上传照片
- (IBAction)cancleChosePhoto:(id)sender {
    _changeImageView.hidden = YES;
    _maskButton.hidden = YES;
}

#pragma mark == 修改用户类型
- (IBAction)changeUserType:(id)sender {
    if (!_isRegistered) {
        return;
    }
    UIStoryboard *secondStroyBoard = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
    ChoosePageViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ChoosePage"];
    
    
    page.bock = ^(NSString* str) {
        _userType.text = str;
    };
    
    [self presentViewController:page animated:YES completion:nil];

}


#pragma mark - 上传图片--------------------------
- (void)imageUpload:(int)numberImg:(UIImage *)imageImage{
    NSString *url = [NSString stringWithFormat:@"%@",IP_Address_IMAGE];
    //分界线的标识符
    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
    //根据url初始化request
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10];
    //分界线 --AaB03x
    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
    //结束符 AaB03x--
    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
    //要上传的图片
    //    UIImage *image=[params objectForKey:@"pic"];
    //得到图片的data
    CGSize newSize = CGSizeMake(80, 80);
    UIGraphicsBeginImageContext(newSize);
    [imageImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* data  = UIImageJPEGRepresentation(newImage, 0.7);
    //http body的字符串
    NSMutableString *body=[[NSMutableString alloc]init];
    //设置HTTPHeader中Content-Type的值
    NSString* content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
    ////添加分界线，换行
    [body appendFormat:@"%@\r\n",MPboundary];
    //声明pic字段，文件名为boris.png
    [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
    //声明上传文件的格式
    [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
    //    [body appendFormat:@"Content-Type: %@\r\n\r\n",content];
    //声明结束符：--AaB03x--
    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
    //声明myRequestData，用来放入http body
    NSMutableData *myRequestData=[NSMutableData data];
    //将body字符串转化为UTF8格式的二进制
    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
    //将image的data加入
    [myRequestData appendData:data];
    //加入结束符--AaB03x--
    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *headerUserAgent=@"";
    if ([Common getLoginStatus]) {
        NSString *userName = [[Common getLoginInfo] objectForKey:Key_User_nickname];
        NSString *userId  = [NSString stringWithFormat:@"%@",[[Common getLoginInfo] objectForKey:Key_User_userId]];
        NSString *encryptPwd  = [ [Common getLoginInfo] objectForKey:Key_User_password];
        NSString *localUserIdentify  = [[UIDevice currentDevice].identifierForVendor UUIDString];
        headerUserAgent = [NSString stringWithFormat:@"%@|%@|%@|%@",userName,userId,encryptPwd,localUserIdentify];
    }else{
        headerUserAgent = @"|||";
    }
    
    //设置HTTPHeader
    [request setValue:content forHTTPHeaderField:@"Content-Type"];
    //设置User-Agent
    [request setValue:headerUserAgent forHTTPHeaderField:@"User-Agent"];
    //设置Content-Length
    [request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"];
    //设置http body
    [request setHTTPBody:myRequestData];
    //http method
    [request setHTTPMethod:@"POST"];
    
    //建立连接，设置代理
    //    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    //上传文件开始
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //获得返回值
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    NSData *jsonData = [returnString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSMutableDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    
    //取得返回的图片名
    //    NSArray* array = [returnString componentsSeparatedByString:@"###"];
    //    NSString * image = [NSString stringWithFormat:@"%@", dictionary[@"result"][0][@"simaId"]];
    NSString * image = dictionary[@"title"];
    if (image.length>0){
        _headImageStr = image;
    }else{
        _headImageStr = @"";
    }
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag == GS_GS_appUserRegister) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
           [[CWHUDTips sharedInstance]  showTips:@"注册成功"  withStatus:2 dismissAfter:2];
            [self dismissViewControllerAnimated:YES completion:^{
                _pageFinishBlock();
            }];
        }
    }else  if (tag==GS_GS_queryMemberInfoById) {
        
      if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
        
                    [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        
        }else  {
            NSDictionary * dic = database[@"result"];
                    //头像
            NSString * image = dic[@"museImage"];
            if (![dic[@"museImage"] isEqual:[NSNull null]]) {
                    if (image.length>0) {
                    _headImageStr = image;
                    [_personHead sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
                    }
                }
                    //性别
                    NSString *sex = [NSString stringWithFormat:@"%@",dic[@"museSex"]];
                    if ([sex isEqualToString:@"1"]) {
                        _sexButton.ifSelected = YES;
                    } else if ([sex isEqualToString:@"2"]) {
                        _sexButton.ifSelected = NO;
                    }
                    //昵称
                    if([dic[@"museNickName"] isEqual:[NSNull null]]){
                        _nickNameLabel.text = @"";
                    }else{
                       _nickNameLabel.text = [NSString stringWithFormat:@"%@",dic[@"museNickName"]];
                    }
        
                    //生日
                    NSString * brithday = [NSString stringWithFormat:@"%@",dic[@"museBirthday"]];
                    if (brithday.length>=10) {
                        _birthdayField.text = [NSString stringWithFormat:@"%@",[brithday substringToIndex:10]];
                    }
                    //电话
                    if([dic[@"musePhone"] isEqual:[NSNull null]]){
                        self.phoneNomber.text = @"";
                    }else{
                        self.phoneNomber.text = [NSString stringWithFormat:@"%@",dic[@"musePhone"]];
                    }
                    //邮箱
                    if([dic[@"museEmail"] isEqual:[NSNull null]]){
                        self.email.text = @"";
                    }else{
                        self.email.text = [NSString stringWithFormat:@"%@",dic[@"museEmail"]];
                    }
                    //名字
                    if([dic[@"museTrueName"] isEqual:[NSNull null]]){
                        self.nameLabel.text = @"";
                    }else{
                        self.nameLabel.text = [NSString stringWithFormat:@"%@",dic[@"museTrueName"]];
                    }
            //用户类型
            if([dic[@"museType"] isEqual:[NSNull null]]){
                self.userType.text = @"";
            }else{
//                NSArray * array = @[@"工程公司",@"设计师",@"建材零售商"];
//                NSInteger type = [dic[@"museType"]integerValue];
//                self.userType.text = array[type-4];
            }
            
            //居住地
            if([dic[@"museAddress"] isEqual:[NSNull null]]){
                self.addressField.text = @"";
            }else{
                self.addressField.text = [NSString stringWithFormat:@"%@",dic[@"museAddress"]];
            }
            
            //身份证
            if([dic[@"museIdcardNo"] isEqual:[NSNull null]]){
                self.idCdard.text = @"";
            }else{
                self.idCdard.text = [NSString stringWithFormat:@"%@",dic[@"museIdcardNo"]];
            }
            
            //公司名字
            if([dic[@"museCompanyName"] isEqual:[NSNull null]]){
                self.companyName.text = @"";
            }else{
                self.companyName.text = [NSString stringWithFormat:@"%@",dic[@"museCompanyName"]];
            }
            
        }
            }else if(tag == GS_GS_updateMember){
            if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
                
                [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
                
            }else  {
                [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:2 dismissAfter:1.5];
                    [self backBtn];
                }
        }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
        
        [self dismissWaitDialog];
        
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
